Vue.component('add-member', {//添加用户组件
    template: `<el-dialog title="添加用户" :visible.sync="visibleDialog" width="700px">
    <el-form ref="contract" :model="form" :rules="rules" :inline-message="true">
        <el-descriptions :column="1" border size="small">
            <el-descriptions-item label="姓名">
                <el-form-item prop="Member_Name">
                    <el-input v-model.trim="form.Member_Name" placeholder="请输入姓名"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="客户手机号">
                <el-form-item prop="Member_SerialNumber">
                    <el-input v-model.trim="form.Member_SerialNumber" placeholder="请输入客户手机号"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="客户邮箱">
                <el-form-item prop="Email">
                    <el-input v-model.trim="form.Email" placeholder="请输入客户邮箱"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="性别">
                <el-form-item prop="Sex">
                    <el-radio-group v-model.trim="form.Sex">
                        <el-radio label="0">男</el-radio>
                        <el-radio label="1">女</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="所属部门">
                <el-form-item prop="Department">
                    <el-cascader v-model="Department" filterable :props="defaultProps" :options="data" style="width: 100%"></el-cascader>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="备注">
                <el-form-item prop="Member_Notes">
                    <el-input type="textarea" placeholder="请输入内容" v-model.trim="form.Member_Notes" maxlength="50" show-word-limit></el-input>
                </el-form-item>
            </el-descriptions-item>
        </el-descriptions>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:visible',false)">取消</el-button>
        <el-button :loading="loading" type="primary" @click="submitForm('contract')">提交</el-button>
    </span></el-dialog>`,
    props: ['data', 'visible'],
    data() {
        const validator = (rule, value, callback) => {
            if (!validatemobile(this.form.Member_SerialNumber)) {
                callback(new Error('请输入有效手机号'));
            } else {
                callback();
            }
        }
        return {
            visibleDialog: false,
            form: {
                Member_SerialNumber: '',
                Member_Name: '',
                Member_Notes: '',
                Email: '',
                Image: '',
                Sex: '0',
                Children: {
                    business_member_department: [],
                }
            },
            Department: [],
            rules: {
                Member_SerialNumber: [{ required: true, validator, trigger: 'blur' }],
                Member_Name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
            },
            loading: false,
            defaultProps: {
                children: 'Children',
                label: 'Department_Name',
                value: 'Department_SerialNumber',
                checkStrictly: true,
                multiple: true
            },
        }
    },
    watch: {
        visible() {
            this.visibleDialog = this.visible
        },
        visibleDialog(val) {
            this.$emit('update:visible', val)
        },
    },
    methods: {
        submitForm(formName) {
            const that = this;
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    if (that.Department.length == 0) {
                        that.$message({
                            message: "请选择部门",
                            type: 'warning'
                        })
                        return false;
                    }
                    that.loading = true;
                    that.form.Creation_Datetime = getYMDHMSDate();
                    that.form.Department_JSON = JSON.stringify(that.Department);
                    that.Department.forEach(item => {
                        that.form.Children.business_member_department.push({
                            Member_Department_SerialNumber: that.form.Member_SerialNumber + '_' + (item[item.length - 1]),
                            Member_SerialNumber: that.form.Member_SerialNumber,
                            Department_SerialNumber: item[item.length - 1],
                        })
                    })
                    console.log(that.form.Children.business_member_department);
                    $.ajax({
                        headers: requestHeaders(),
                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                        type: 'POST',
                        data: {
                            Data: JSON.stringify({
                                Add: {
                                    business_member_info: [that.form],
                                    base_operation_log: [generateLog('添加用户(' + that.form.Member_Name + ')', '平台端操作', 'business_member_info', JSON.stringify({ Add: { business_member_info: [that.form] } }))]
                                }
                            })
                        },
                        success: function (res) {
                            if (res.Status === 'success') {
                                that.form = {
                                    Member_SerialNumber: '',
                                    Member_Name: '',
                                    Member_Notes: '',
                                    Email: '',
                                    Image: '',
                                    Sex: '0',
                                    Children: {
                                        business_member_department: [],
                                    },
                                    Department_JSON: '',
                                }
                                that.Department = [],
                                    that.$message.success("提交成功")
                                that.$emit('update:visible', false)
                                that.$emit('success')
                            } else {
                                that.$message.error("提交失败，该手机号已存在")
                            }
                            that.form.Children.business_member_department = [];
                        },
                        error: function () {
                            that.$message.error("系统繁忙")
                        },
                        complete: function (XMLHttpRequest) {
                            that.loading = false
                            requestPretreatment(XMLHttpRequest);
                        },
                        dataType: "json"
                    })
                } else {
                    that.$message({
                        message: sumberError,
                        type: 'warning'
                    })
                    return false;
                }
            })
        }
    },
})
Vue.component('edit-member', {//修改用户
    template: `<el-dialog title="修改用户" :visible.sync="visibleDialog" width="700px">
    <el-form ref="contract" :model="form" :rules="rules" :inline-message="true">
        <el-descriptions :column="1" border size="small">
            <el-descriptions-item label="姓名">
                <el-form-item prop="Member_Name">
                    <el-input v-model.trim="form.Member_Name" placeholder="请输入姓名"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="客户手机号">
                <el-form-item prop="Member_SerialNumber">
                    <el-input v-model.trim="form.Member_SerialNumber" placeholder="请输入客户手机号"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="客户邮箱">
                <el-form-item prop="Email">
                    <el-input v-model.trim="form.Email" placeholder="请输入客户邮箱"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="性别">
                <el-form-item prop="Sex">
                    <el-radio-group v-model.trim="form.Sex">
                        <el-radio label="0">男</el-radio>
                        <el-radio label="1">女</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="所属部门">
                <el-form-item prop="Department">
                    <el-cascader v-model="Department" filterable :props="defaultProps" :options="data" style="width: 100%"></el-cascader>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="备注">
                <el-form-item prop="Member_Notes">
                    <el-input type="textarea" placeholder="请输入内容" v-model.trim="form.Member_Notes" maxlength="50" show-word-limit></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="绑定微信">
                <el-form-item prop="Member_Notes">
                    <el-input disabled v-model.trim="form.Open_ID" placeholder="暂未绑定微信"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <!-- <el-descriptions-item label="解绑微信" v-if="form.Open_ID">
                <el-form-item prop="Member_Notes">
                    <el-switch v-model="isOpen_ID" active-text="是" inactive-text="否"></el-switch>
                </el-form-item>
            </el-descriptions-item>-->
        </el-descriptions>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:visible',false)">取消</el-button>
        <el-button :loading="loading" type="primary" @click="submitForm('contract')">提交</el-button>
    </span></el-dialog>`,
    props: ['data', 'id', 'visible'],
    data() {
        const validator = (rule, value, callback) => {
            if (!validatemobile(this.form.Member_SerialNumber)) {
                callback(new Error('请输入有效手机号'));
            } else {
                callback();
            }
        }
        return {
            visibleDialog: false,
            form: {
                Member_SerialNumber: '',
                Member_Name: '',
                Member_Notes: '',
                Email: '',
                Image: '',
                Sex: '0',
                Department_JSON: '',
                Children: {
                    business_member_department: [],
                },
            },
            isOpen_ID: false,
            Department: [],
            rules: {
                Member_SerialNumber: [{ required: true, validator, trigger: 'blur' }],
                Member_Name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
            },
            loading: false,
            defaultProps: {
                children: 'Children',
                label: 'Department_Name',
                value: 'Department_SerialNumber',
                checkStrictly: true,
                multiple: true
            },
        }
    },
    watch: {
        visible() {
            this.visibleDialog = this.visible
        },
        visibleDialog(val) {
            this.$emit('update:visible', val)
            if (val) {
                this.isOpen_ID = false;
                this.getData(this.id);
            }
        },
    },
    methods: {
        getData(DocumentSerialNumber) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalGetDataStructure`,
                type: 'POST',
                data: {
                    DocumentSerialNumber,
                    Data: JSON.stringify({ business_member_info: { business_member_department: {} } }),
                    Condition: ""
                },
                success: function (data) {
                    if (data.business_member_info.length == 1) {
                        that.form = data.business_member_info[0];
                        that.Department = that.form.Department_JSON;
                    }
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        Open_ID(callback) {
            const that = this;
            if (this.isOpen_ID) {
                $.ajax({
                    headers: requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                    type: 'POST',
                    data: {
                        Data: "business_member_account_info",
                        Condition: "Open_ID='" + that.form.Open_ID + "'"
                    },
                    success: function (business_member_account_info) {
                        if (business_member_account_info.length == 1) {
                            business_member_account_info[0].Cash_Point = '0';
                            business_member_account_info[0].Cash_Point_Sales = '0';
                            business_member_account_info[0].Cash_Point_Balance = '0';
                            callback({ business_member_account_info })
                        }
                    },
                    complete: function (XMLHttpRequest) {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json"
                });
            } else {
                callback({});
            }
        },
        submitForm(formName) {
            const that = this;
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    that.loading = true;
                    //筛出删除的部门
                    that.form.Children.business_member_department.forEach(item => {
                        if (!that.Department.some(i => i[i.length - 1] == item.Department_SerialNumber)) {
                            item.Row_Status = '1';
                        }
                    })
                    //筛出恢复删除的部门
                    that.Department.forEach(item => {
                        if (that.form.Children.business_member_department.some(i => item[item.length - 1] == i.Department_SerialNumber)) {
                            that.form.Children.business_member_department.filter(i => item[item.length - 1] == i.Department_SerialNumber)[0].Row_Status = '0'
                        }
                    })
                    //更新新部门
                    that.form.Department_JSON = JSON.stringify(that.Department);
                    that.Department.forEach(item => {
                        if (!that.form.Children.business_member_department.some(i => i.Department_SerialNumber == item[item.length - 1])) {
                            that.form.Children.business_member_department.push({
                                Member_Department_SerialNumber: that.form.Member_SerialNumber + '-' + item[item.length - 1],
                                Member_SerialNumber: that.form.Member_SerialNumber,
                                Department_SerialNumber: item[item.length - 1],
                            })
                        }
                    })

                    that.Open_ID((business_member_account_info) => {
                        const { add, modify } = that.deal()
                        if (that.isOpen_ID) {
                            modify.Open_ID = '';
                        }
                        let data = {}
                        if (add == null) {
                            data = {
                                Data: JSON.stringify({
                                    Modify: { business_member_info: [modify], ...business_member_account_info },
                                    Add: { base_operation_log: [generateLog('修改用户信息', '平台端操作', 'business_member_info', JSON.stringify({ Modify: { business_member_info: [modify], ...business_member_account_info } }))] }
                                })
                            }
                        } else {
                            data = {
                                Data: JSON.stringify({
                                    Modify: { business_member_info: [modify], ...business_member_account_info },
                                    Add: { business_member_info: [add], base_operation_log: [generateLog('修改用户信息', '平台端操作', 'business_member_info', JSON.stringify({ Modify: { business_member_info: [modify], ...business_member_account_info }, Add: { business_member_info: [add] } }))] },
                                }),
                            }
                        }
                        $.ajax({
                            headers: requestHeaders(),
                            url: `${BASE_URL2}/generalBusiness/generalSave`,
                            type: 'POST',
                            data,
                            success: function (res) {
                                if (res.Status === 'success') {
                                    that.form = {
                                        Member_SerialNumber: '',
                                        Member_Name: '',
                                        Member_Notes: '',
                                        Email: '',
                                        Image: '',
                                        Sex: '0',
                                        Department_JSON: '',
                                        Children: {
                                            business_member_department: [],
                                        },
                                    }
                                    that.Department = [],
                                        that.$message.success("提交成功")
                                    that.$emit('update:visible', false)
                                    that.$emit('success')
                                } else {
                                    that.$message.error("提交失败，请稍后再试")
                                }
                            },
                            error: function () {
                                that.$message.error("提交失败，该手机号已存在")
                            },
                            complete: function (XMLHttpRequest) {
                                that.loading = false
                                requestPretreatment(XMLHttpRequest);
                            },
                            dataType: "json"
                        })
                    })
                } else {
                    that.$message({
                        message: sumberError,
                        type: 'warning'
                    })
                    return false;
                }
            })
        },
        deal() {
            const add = deepClone(this.form)
            const modify = deepClone(this.form)

            let add_business_member_department = [], modify_business_member_department = [];

            for (const i in modify.Children.business_member_department) {
                const obj = modify.Children.business_member_department[i];
                if (!Object.keys(obj).some(item => item.includes('_Original'))) {
                    add_business_member_department.push(obj)
                } else {
                    modify_business_member_department.push(obj)
                }
            }

            add.Children.business_member_department = add_business_member_department;
            modify.Children.business_member_department = modify_business_member_department;

            if (add_business_member_department.length == 0) {
                return { add: null, modify };
            }

            return { add, modify };
        },
    },
})
Vue.component('add-department', {//添加部门组件
    template: `<el-dialog :title="form.Level==1?'添加部门':'添加子部门'" :visible.sync="visibleDialog" width="700px">
    <el-form ref="contract" :model="form" :rules="rules" :inline-message="true">
        <el-descriptions :column="1" border size="small">
            <el-descriptions-item label="部门名称">
                <el-form-item prop="Department_Name">
                    <el-input v-model.trim="form.Department_Name" placeholder="请输入部门名称"></el-input>
                </el-form-item>
            </el-descriptions-item>
        </el-descriptions>
        <div class="table_titel">
            <div class="titel">添加用户</div>
            <div class="operation">
                <el-button type="text" size="small" @click="add_user">新增</el-button>
                <el-button type="text" size="small" @click="remove_user">删除</el-button>
            </div>
        </div>
        <el-descriptions :column="2" v-for="(item,index) in form.User" :key="index" border size="small">
            <el-descriptions-item :label="index + 1 + '.姓名'">
                <el-form-item prop="Member_Name">
                    <el-input v-model.trim="item.Member_Name" placeholder="请输入姓名"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="客户手机号">
                <el-form-item prop="Member_SerialNumber">
                    <el-input v-model.trim="item.Member_SerialNumber" placeholder="请输入客户手机号"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="客户邮箱">
                <el-form-item prop="Email">
                    <el-input v-model.trim="item.Email" placeholder="请输入客户邮箱"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="性别">
                <el-form-item prop="Sex">
                    <el-radio-group v-model="item.Sex">
                        <el-radio label="0">男</el-radio>
                        <el-radio label="1">女</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="备注">
                <el-form-item prop="Member_Notes">
                    <el-input type="textarea" placeholder="请输入内容" v-model.trim="item.Member_Notes" maxlength="50" show-word-limit></el-input>
                </el-form-item>
            </el-descriptions-item>
        </el-descriptions>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:visible',false)">取消</el-button>
        <el-button :loading="loading" type="primary" @click="submitForm('contract')">提交</el-button>
    </span></el-dialog>`,
    props: ['data', 'node', 'visible'],
    data() {
        return {
            visibleDialog: false,
            Icon: [],//图标库
            form: {
                Department_SerialNumber: '',
                ...this.data,
                Department_Name: '',
                User: []
            },
            rules: {
                Department_Name: [{ required: true, message: '请输入部门名称', trigger: 'blur' }],
            },
            loading: false,
        }
    },
    watch: {
        visible() {
            this.visibleDialog = this.visible;
        },
        visibleDialog(val) {
            this.$emit('update:visible', val)
        },
        'data.Parent_SerialNumber': function (newVal) {
            this.form.Parent_SerialNumber = newVal;
        },
        'data.Level': function (newVal) {
            this.form.Level = newVal;
        },
    },
    computed:{
        Department_JSON(){
            let arr = [];
            if (this.node != null) {
                return this.addDepartment(this.node,arr);
            }else{
                return [];
            }
        }
    },
    methods: {
        addDepartment(node,arr){
            if (node.parent != null) {
                arr = [node.data.Department_SerialNumber,...arr]
                return this.addDepartment(node.parent,arr);
            } 
            return arr;
        },
        add_user() {
            this.form.User.push({
                Member_Name: '',
                Member_SerialNumber: '',
                Email: '',
                Sex: '0',
                Member_Notes: '',
            })
        },
        remove_user() {
            this.form.User.pop();
        },
        submitForm(formName) {
            const that = this;
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    that.loading = true;
                    $.ajax({
                        headers: requestHeaders(),
                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                        type: 'POST',
                        data: {
                            Data: JSON.stringify({
                                Add: {
                                    business_department_info: [that.form],
                                }
                            })
                        },
                        success: function (res) {
                            //
                            if (res.Status === 'success') {
                                if (that.form.User.length > 0) {
                                    let business_member_info = [];
                                    that.form.User.forEach(item => {
                                        business_member_info.push({
                                            ...item,
                                            Creation_Datetime:getYMDHMSDate(),
                                            Department_JSON: JSON.stringify([[...that.Department_JSON,res.Data]]),
                                            Children: {
                                                business_member_department: [{
                                                    Member_Department_SerialNumber: item.Member_SerialNumber + "-" + res.Data,
                                                    Member_SerialNumber: item.Member_SerialNumber,
                                                    Department_SerialNumber: res.Data
                                                }]
                                            }
                                        })
                                    })
                                    $.ajax({
                                        headers: requestHeaders(),
                                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                                        type: 'POST',
                                        data: {
                                            Data: JSON.stringify({ Add: { 
                                                business_member_info, 
                                                base_operation_log: [
                                                    generateLog('添加部门信息', '平台端操作', 'business_department_info', JSON.stringify({ Add: { business_department_info: [that.form] } })),
                                                    generateLog('添加用户信息', '平台端操作', 'business_member_info', JSON.stringify({ Add: { business_member_info } })),
                                                ],
                                            }})
                                        },
                                        success: function (res) {
                                            if (res.Status === 'success') {
                                                that.form = { Department_SerialNumber: '', ...that.data, Department_Name: '', User: [] }
                                                that.$message.success("提交成功")
                                                that.$emit('update:visible', false)
                                                that.$emit('success')
                                            } else {
                                                that.$message.error("用户提交失败，存在已录入的用户")
                                            }
                                        },
                                        complete: function (XMLHttpRequest) {
                                            that.loading = false
                                            requestPretreatment(XMLHttpRequest);
                                        },
                                        dataType: "json"
                                    })
                                } else {
                                    that.loading = false
                                    that.form = { Department_SerialNumber: '', ...that.data, Department_Name: '', User: [] }
                                    that.$message.success("提交成功")
                                    that.$emit('update:visible', false)
                                    that.$emit('success')
                                }
                            } else {
                                that.loading = false
                                that.$message.error("提交失败，请稍后再试")
                            }
                        },
                        error: function () {
                            that.loading = false
                        },
                        complete: function (XMLHttpRequest) {
                            requestPretreatment(XMLHttpRequest);
                        },
                        dataType: "json"
                    })
                } else {
                    that.$message({
                        message: sumberError,
                        type: 'warning'
                    })
                    return false;
                }
            })
        }
    },
})
Vue.component('edit-department', {//修改部门组件
    template: `<el-dialog title="修改部门" :visible.sync="visibleDialog" width="700px">
    <el-form ref="contract" :model="form" :rules="rules" :inline-message="true">
        <el-descriptions :column="1" border size="small">
            <el-descriptions-item label="部门名称">
                <el-form-item prop="Department_Name">
                    <el-input v-model.trim="form.Department_Name" placeholder="请输入部门名称"></el-input>
                </el-form-item>
            </el-descriptions-item>
        </el-descriptions>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:visible',false)">取消</el-button>
        <el-button :loading="loading" type="primary" @click="submitForm('contract')">提交</el-button>
    </span></el-dialog>`,
    props: ['data', 'id', 'visible'],
    data() {
        return {
            visibleDialog: false,
            form: {
                Department_SerialNumber: '',
                Department_Name: '',
            },
            rules: {
                Department_Name: [{ required: true, message: '请输入部门名称', trigger: 'blur' }],
            },
            loading: false,
        }
    },
    watch: {
        visible() {
            this.visibleDialog = this.visible;
        },
        visibleDialog(val) {
            this.$emit('update:visible', val)
            if (val) {
                this.loading = true,
                    this.getData(this.id);
            }
        },
    },
    methods: {
        getData(Department_SerialNumber) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                type: 'POST',
                data: {
                    Data: "business_department_info",
                    Condition: "Department_SerialNumber='" + Department_SerialNumber + "'"
                },
                success: function (data) {
                    if (data.length == 1) {
                        that.form = data[0];
                    }
                },
                complete: function (XMLHttpRequest) {
                    that.loading = false;
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        submitForm(formName) {
            const that = this;
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    that.loading = true;
                    $.ajax({
                        headers: requestHeaders(),
                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                        type: 'POST',
                        data: {
                            Data: JSON.stringify({
                                Modify: { business_department_info: [that.form] },
                                Add: { base_operation_log: [generateLog('修改部门信息', '平台端操作', 'business_department_info', JSON.stringify({ Modify: { business_department_info: [that.form] } }))] }
                            })
                        },
                        success: function (res) {
                            if (res.Status === 'success') {
                                that.form = { Department_SerialNumber: '', Department_Name: '', }
                                that.$message.success("提交成功")
                                that.$emit('update:visible', false)
                                that.$emit('success')
                            } else {
                                that.$message.error("提交失败，请稍后再试")
                            }
                        },
                        complete: function (XMLHttpRequest) {
                            that.loading = false
                            requestPretreatment(XMLHttpRequest);
                        },
                        dataType: "json"
                    })
                } else {
                    that.$message({
                        message: sumberError,
                        type: 'warning'
                    })
                    return false;
                }
            })
        }
    },
})
Vue.component('integral', {//设置积分
    template: `<el-dialog title="修改会员积分" :visible.sync="visibleDialog" width="700px">
    <el-form ref="contract" :model="form" :rules="rules" :inline-message="true">
        <el-descriptions :column="1" border size="small">
            <el-descriptions-item label="账单标题">
                <el-form-item prop="Points_Title">
                    <el-input v-model.trim="form.Points_Title" placeholder="请输入账单标题"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="所属活动">
                <el-form-item prop="Activity_SerialNumber">
                    <el-select style="width:100%" v-model="form.Activity_SerialNumber" placeholder="请选择所属活动">
                        <el-option v-for="item in activity_zl" :key="item.Activity_SerialNumber" :label="item.Activity_Name" :value="item.Activity_SerialNumber"></el-option>
                    </el-select>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item v-if="form.Activity_SerialNumber" label="对应部门">
                <el-form-item prop="Department_SerialNumber">
                    <el-select style="width:100%" v-model="form.Department_SerialNumber" placeholder="请选择部门"
                        :disabled="activity_zl.filter(i=>i.Activity_SerialNumber==form.Activity_SerialNumber)[0].Department.length == 1">
                        <el-option v-for="item in activity_zl.filter(i=>i.Activity_SerialNumber==form.Activity_SerialNumber)[0].Department" 
                            :key="item.Department_SerialNumber" :label="item.Department_Name+'(剩余积分:'+ item.Remain_Points +')'" :value="item.Department_SerialNumber"></el-option>
                    </el-select>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="修改积分">
                <el-form-item prop="Type">
                    <el-radio-group v-model="form.Type">
                        <el-radio label="0">增加</el-radio>
                        <el-radio label="1">减少</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="积分">
                <el-form-item prop="Points">
                    <el-input-number v-model.trim="form.Points" :min="1"></el-input-number>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="备注">
                <el-form-item prop="Department_Name">
                    <el-input type="textarea" :autosize="{ minRows: 2}" maxlength="100"
                    show-word-limit placeholder="请输入内容"  v-model="form.Notes"></el-input>
                </el-form-item>
            </el-descriptions-item>
        </el-descriptions>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:visible',false)">取消</el-button>
        <el-button :loading="loading" type="primary" @click="submitForm('contract')">提交</el-button>
    </span></el-dialog>`,
    props: ['id', 'Open_ID', 'visible'],
    data() {
        return {
            visibleDialog: false,
            form: {
                Log_SerialNumber: '',
                Member_SerialNumber: '',
                Points_Title: '管理员增加积分',
                Activity_SerialNumber: '',
                Department_SerialNumber: '',
                Points_Type: 'Cash',
                Type: '0',
                Points: 1,
                Remain_Points: 0,
                Notes: '',
            },
            rules: {
                Activity_SerialNumber: [{ required: true, message: '请选择活动', trigger: 'change' }],
                Department_SerialNumber: [{ required: true, message: '请选择分配部门', trigger: 'change' }]
            },
            member: {},
            activity: [],
            loading: false,
        }
    },
    computed: {
        activity_zl() {
            let arr = [];
            this.activity.forEach(item => {
                let obj = {
                    Department_SerialNumber: item.Department_SerialNumber,
                    Department_Name: item.Department_Name,
                    Remain_Points: item.Remain_Points
                }
                let activity = arr.filter(i => i.Activity_SerialNumber == item.Activity_SerialNumber)[0];
                if (activity) {
                    activity.Department.push(obj)
                } else {
                    arr.push({
                        Activity_SerialNumber: item.Activity_SerialNumber,
                        Activity_Name: item.Activity_Name,
                        Department: [obj]
                    })
                }
            })
            return arr;
        }
    },
    watch: {
        visible() {
            this.visibleDialog = this.visible;
        },
        visibleDialog(val) {
            this.$emit('update:visible', val)
            if (val) {
                this.loading = true,
                    this.getData(this.id);
            }
        },
        'form.Type'(val) {
            if (val == '0') {
                this.form.Points_Title = "管理员增加积分"
            } else {
                this.form.Points_Title = "管理员扣减积分"
            }
        },
        'form.Activity_SerialNumber'(val) {
            let arr = this.activity_zl.filter(i => i.Activity_SerialNumber == val)[0].Department;
            if (arr.length == 1) {
                this.form.Department_SerialNumber = arr[0].Department_SerialNumber
            }
        }
    },
    methods: {
        getData(Member_SerialNumber) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
                type: 'POST',
                data: {
                    SQLSerialNumber: 'A_business_activity_member',
                    Condition: window.btoa(unescape(encodeURIComponent(Member_SerialNumber))),
                    ExtensionCondition: ''
                },
                success: function (res) {
                    that.activity = res;
                },
                error: function () {
                    that.$message.error("操作失败，请稍后再试")
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                type: 'POST',
                data: {
                    Data: "business_member_info",
                    Condition: "Member_SerialNumber='" + Member_SerialNumber + "'"
                },
                success: function (data) {
                    if (data.length == 1) {//修改
                        that.member = data[0];
                    }
                },
                complete: function (XMLHttpRequest) {
                    that.loading = false;
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        submitForm(formName) {
            const that = this;
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    that.loading = true;
                    $.ajax({//查询账户信息
                        headers: requestHeaders(),
                        url: `${BASE_URL2}/member/getMemberPoint`,
                        type: 'POST',
                        data: {
                            Data: JSON.stringify([{
                                tableName: 'business_member_account_info',
                                Condition: window.btoa(unescape(encodeURIComponent("Open_ID='" + that.Open_ID + "'"))),
                            }, {
                                tableName: 'business_member_cash_points',
                                Condition: window.btoa(unescape(encodeURIComponent("Member_SerialNumber='" + that.id
                                    + "' AND Activity_SerialNumber='" + that.form.Activity_SerialNumber
                                    + "' AND Department_SerialNumber='" + that.form.Department_SerialNumber + "'"))),
                            }]),
                        },
                        success: function (res) {
                            let business_member_cash_points = res.business_member_cash_points,
                                business_member_account_info = res.business_member_account_info,
                                Member_SerialNumber = that.id,
                                Activity_SerialNumber = that.form.Activity_SerialNumber,
                                Department_SerialNumber = that.form.Department_SerialNumber,
                                Points = that.form.Points, is = false;
                            //用户是否首次参加该活动
                            if (business_member_cash_points.length == 0) {
                                business_member_cash_points.push({
                                    Member_Points_SerialNumber: '',
                                    Member_SerialNumber,
                                    Activity_SerialNumber,
                                    Department_SerialNumber,
                                    Total_Points: 0,
                                    Remain_Points: 0,
                                    Sales_Points: 0,
                                })
                                is = true;//是否首次参加活动
                            }

                            //生成积分修改日志
                            let business_member_points_log = [{
                                ...deepClone(that.form),
                                Member_SerialNumber
                            }]
                            //1.判断变动积分值是正还是负数
                            if (that.form.Type == "0") {//增加积分
                                business_member_cash_points[0].Total_Points = accAdd(business_member_cash_points[0].Total_Points, Points);
                                business_member_cash_points[0].Remain_Points = accAdd(business_member_cash_points[0].Remain_Points, Points);
                                if (business_member_account_info.length == 1) { //若当前账户已经绑定
                                    business_member_account_info[0].Cash_Point = accAdd(business_member_account_info[0].Cash_Point, Points);
                                    business_member_account_info[0].Cash_Point_Balance = accAdd(business_member_account_info[0].Cash_Point_Balance, Points);
                                }
                                business_member_points_log[0].Points_Type = 'Cash';//收入
                                business_member_points_log[0].Remain_Points = business_member_cash_points[0].Remain_Points;
                            } else {//扣减积分
                                business_member_cash_points[0].Remain_Points = accSub(business_member_cash_points[0].Remain_Points, Points);
                                business_member_cash_points[0].Sales_Points = accAdd(business_member_cash_points[0].Sales_Points, Points);
                                if (business_member_account_info.length == 1) { //若当前账户已经绑定
                                    business_member_account_info[0].Cash_Point_Balance = accSub(business_member_account_info[0].Cash_Point_Balance, Points);
                                    business_member_account_info[0].Cash_Point_Sales = accAdd(business_member_account_info[0].Cash_Point_Sales, Points);
                                }
                                business_member_points_log[0].Points_Type = 'Cash';//扣减
                                business_member_points_log[0].Remain_Points = business_member_cash_points[0].Remain_Points;
                                business_member_points_log[0].Points = '-' + Points
                            }
                            if (business_member_points_log[0].Remain_Points < 0) {//积分剩余不足无法扣减
                                that.$message({
                                    message: '积分剩余不足无法扣减',
                                    type: 'warning'
                                })
                                that.loading = false;
                            } else {
                                let data = {};
                                if (is) {//判断是否首次参与活动
                                    if (business_member_account_info.length == 1) {
                                        data = {
                                            Data: JSON.stringify({
                                                Add: { business_member_points_log, business_member_cash_points },
                                                Modify: { business_member_account_info }
                                            })
                                        }
                                    } else {
                                        data = {
                                            Data: JSON.stringify({
                                                Add: { business_member_points_log, business_member_cash_points },
                                            })
                                        }
                                    }
                                } else {
                                    if (business_member_account_info.length == 1) {
                                        data = {
                                            Data: JSON.stringify({
                                                Add: { business_member_points_log },
                                                Modify: { business_member_account_info, business_member_cash_points }
                                            })
                                        }
                                    } else {
                                        data = {
                                            Data: JSON.stringify({
                                                Add: { business_member_points_log },
                                                Modify: { business_member_cash_points }
                                            })
                                        }
                                    }
                                }
                                $.ajax({
                                    headers: requestHeaders(),
                                    url: `${BASE_URL2}/generalBusiness/generalSave`,
                                    type: 'POST',
                                    data,
                                    success: function (res) {
                                        if (res.Status === 'success') {
                                            that.form = {
                                                Log_SerialNumber: '',
                                                Member_SerialNumber: '',
                                                Points_Title: '管理员增加积分',
                                                Activity_SerialNumber: '',
                                                Department_SerialNumber: '',
                                                Points_Type: 'Cash',
                                                Type: '0',
                                                Points: 1,
                                                Remain_Points: 0,
                                                Notes: '',
                                            },
                                                that.$message.success("提交成功");
                                            that.$emit('update:visible', false)
                                            that.$emit('success')
                                        } else {
                                            that.$message.error("提交失败，请稍后再试")
                                        }
                                    },
                                    complete: function (XMLHttpRequest) {
                                        that.loading = false
                                        requestPretreatment(XMLHttpRequest);
                                    },
                                    dataType: "json"
                                })
                            }
                        },
                        complete: function (XMLHttpRequest) {
                            requestPretreatment(XMLHttpRequest, false, (err) => {
                                if (err == 'error') {
                                    that.$message.error("系统繁忙!")
                                }
                            });
                        },
                        dataType: "json"
                    });
                }
            })
        }
    },
})
Vue.component('invoice', {//开票管理
    template: `<el-dialog title="开票主体管理" :visible.sync="visibleDialog" width="1200px">
    <el-table v-if="tab==0" :data="tableData" stripe border max-height="55vh" style="width: 100%">
        <el-table-column align="center" type="index" label="序号" width="50"></el-table-column>
        <el-table-column align="center" prop="Enterprise_Name" show-overflow-tooltip label="公司抬头"></el-table-column>
        <el-table-column align="center" prop="Enterprise_Province" show-overflow-tooltip label="公司地址">
            <template v-slot="{row}">
                {{row.Enterprise_Province}}{{row.Enterprise_City}}{{row.Enterprise_County}}{{row.Enterprise_Details}}
            </template>
        </el-table-column>
        <el-table-column align="center" prop="Enterprise_Contacts" show-overflow-tooltip label="联系人"></el-table-column>
        <el-table-column align="center" prop="Enterprise_Phone" show-overflow-tooltip label="联系方式"></el-table-column>
        <el-table-column align="center" prop="Bank_Name" show-overflow-tooltip label="开户行"></el-table-column>
        <el-table-column align="center" prop="Account_Number" show-overflow-tooltip label="银行账户"></el-table-column>
        <el-table-column align="center" label="操作">
            <template v-slot="{row}">
                <el-button type="primary" size="small" @click="Edit(row.Department_Bank_Account_SerialNumber)">编辑</el-button>
                <el-button type="danger" size="small" @click="Remove(row)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-form v-else ref="contract" :model="form" :rules="rules" :inline-message="true">
        <el-descriptions :column="2" border size="small">
            <el-descriptions-item label="公司地址">
                <el-form-item prop="Enterprise_Name">
                    <el-cascader @change="changeAddress" v-model="value" filterable :props="{value:'label'}" :options="city" style="width: 100%"  placeholder="请选择地址"></el-cascader>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="详细地址">
                <el-form-item prop="Enterprise_Details">
                    <el-input :disabled="value.length!=3" v-model.trim="form.Enterprise_Details" placeholder="请输入详细地址"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="联系人">
                <el-form-item prop="Enterprise_Contacts">
                    <el-input v-model.trim="form.Enterprise_Contacts" placeholder="请输入联系人"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="联系方式">
                <el-form-item prop="Enterprise_Phone">
                    <el-input v-model.trim="form.Enterprise_Phone" placeholder="请输入联系方式"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="开户行">
                <el-form-item prop="Bank_Name">
                    <el-input v-model.trim="form.Bank_Name" placeholder="请输入开户行"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="银行账户">
                <el-form-item prop="Account_Number">
                    <el-input v-model.trim="form.Account_Number" placeholder="请输入银行账户"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="公司抬头">
                <el-form-item prop="Enterprise_Name">
                    <el-input v-model.trim="form.Enterprise_Name" placeholder="请输入公司抬头"></el-input>
                </el-form-item>
            </el-descriptions-item>
        </el-descriptions>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:visible',false)">取消</el-button>
        <el-button v-if="tab==0" type="success" @click="Add()">添加开票主体</el-button>
        <template v-else>
            <el-button @click="tab=0">返回</el-button>
            <el-button type="primary" @click="submitForm('contract')">提交</el-button>
        </template>
    </span></el-dialog>`,
    props: ['id', 'visible'],
    data() {
        const validator = (rule, value, callback) => {
            if (!validatemobile(this.form.Enterprise_Phone)) {
                callback(new Error('请输入有效手机号'));
            } else {
                callback();
            }
        }
        return {
            visibleDialog: false,
            tableData: [],
            tab: 0,//0查询 1添加 2修改
            page: {
                SQLSerialNumber: 'P_business_department_bank_account',
                PaginationNumber: 1,//页数
                RowAmount: 20,//每页数据条数
                Condition: '',
                ExtensionCondition: '',
            },
            total: 0,
            form: {},
            rules: {
                Enterprise_Name: [{ required: true, message: '请输入公司抬头', trigger: 'blur' }],
                Enterprise_Details: [{ required: true, message: '请输入详情地址', trigger: 'blur' }],
                Enterprise_Phone: [{ required: true, validator, trigger: 'blur' }],
                Enterprise_Contacts: [{ required: true, message: '请输入联系人', trigger: 'blur' }]
            },
            value: [],
            city: [],
        }
    },
    watch: {
        visible() {
            this.visibleDialog = this.visible;
        },
        visibleDialog(val) {
            this.$emit('update:visible', val);
            if (val) {
                this.page.Condition = window.btoa(encodeURIComponent(this.id));
                this.getList(this.page);
            }
        },
    },
    mounted() {
        this.getData();
    },
    methods: {
        Add() {
            this.form = {
                Department_Bank_Account_SerialNumber: '',
                Department_SerialNumber: this.id,
                Enterprise_Name: '',
                Enterprise_Province: '',
                Enterprise_City: '',
                Enterprise_County: '',
                Enterprise_Details: '',
                Enterprise_Contacts: '',
                Enterprise_Phone: '',
                Bank_Name: '',
                Account_Number: '',
            }
            this.value = []
            this.tab = 1;
        },
        Edit(Department_Bank_Account_SerialNumber) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                data: {
                    Data: "business_department_bank_account",
                    Condition: "Department_Bank_Account_SerialNumber='" + Department_Bank_Account_SerialNumber + "'"
                },
                success: function (data) {
                    if (data.length == 1) {
                        that.form = data[0];
                        that.value = [data[0].Enterprise_Province, data[0].Enterprise_City, data[0].Enterprise_County]
                        that.tab = 2;
                    }
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        Remove(row) {
            const that = this
            this.$confirm('警告！此操作将删除该开票主体, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                row.Row_Status = '1';
                $.ajax({
                    headers: requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalSave`,
                    type: 'POST',
                    data: {
                        Data: JSON.stringify({ Modify: { business_department_bank_account: [row] } })
                    },
                    success: function (res) {
                        if (res.Status === 'success') {
                            that.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            that.getList(that.page);
                        } else {
                            that.$message.error("删除失败，请稍后再试")
                        }
                    },
                    complete: function (XMLHttpRequest) {
                        that.loading = false
                        requestPretreatment(XMLHttpRequest, false, () => {
                            that.$message.error("删除失败，请稍后再试")
                        });
                    },
                    dataType: "json"
                })
            }).catch(() => { });
        },
        changeAddress(val) {
            this.form.Enterprise_Province = val[0];
            this.form.Enterprise_City = val[1];
            this.form.Enterprise_County = val[2];
        },
        getList(data) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                data,
                success: function (Result) {
                    that.tableData = Result.Rows;
                    that.total = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        getData() {
            const that = this;
            $.ajax({
                url: absolutepath() + "utils/city.json",
                type: "GET",
                success: function (data) {
                    that.city = data
                },
                dataType: "json"
            })
        },
        submitForm(formName) {
            const that = this;
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    that.loading = true;
                    let data = {};
                    if (that.tab == 1) {
                        data = {
                            Data: JSON.stringify({
                                Add: {
                                    business_department_bank_account: [that.form],
                                }
                            })
                        }
                    } else if (that.tab == 2) {
                        data = {
                            Data: JSON.stringify({
                                Modify: {
                                    business_department_bank_account: [that.form],
                                }
                            })
                        }
                    }
                    $.ajax({
                        headers: requestHeaders(),
                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                        type: 'POST',
                        data,
                        success: function (res) {
                            if (res.Status === 'success') {
                                that.$message.success("提交成功")
                                that.getList(that.page)
                                that.tab = 0;
                            } else {
                                that.$message.error("提交失败，请稍后再试")
                            }
                        },
                        complete: function (XMLHttpRequest) {
                            that.loading = false
                            requestPretreatment(XMLHttpRequest, false, () => {
                                that.$message.error("系统繁忙")
                            });
                        },
                        dataType: "json"
                    })
                } else {
                    that.$message({
                        message: sumberError,
                        type: 'warning'
                    })
                    return false;
                }
            })
        }
    }
})
Vue.component('user', {//联系人管理
    template: `<el-dialog title="部门联系人管理" :visible.sync="visibleDialog" width="700px">
    <el-table v-if="tab==0" :data="tableData" stripe border max-height="55vh" style="width: 100%">
        <el-table-column align="center" type="index" label="序号" width="50"></el-table-column>
        <el-table-column align="center" prop="ID_Name" show-overflow-tooltip label="联系人"></el-table-column>
        <el-table-column align="center" prop="User_Number" show-overflow-tooltip label="联系方式"></el-table-column>
        <el-table-column align="center" label="操作">
            <template v-slot="{row}">
                <el-button type="primary" size="small" @click="Edit(row.User_Number)">编辑</el-button>
                <!-- <el-button type="danger" size="small" @click="Remove(row)">删除</el-button> -->
            </template>
        </el-table-column>
    </el-table>
    <el-form v-else ref="contract" :model="form" :rules="rules" :inline-message="true">
        <el-descriptions :column="1" border size="small">
            <el-descriptions-item label="联系人名称">
                <el-form-item prop="Name">
                    <el-input v-model.trim="form.Name" placeholder="请输入联系人姓名"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="姓名">
                <el-form-item prop="ID_Name">
                    <el-input v-model.trim="form.ID_Name" placeholder="请输入姓名"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="手机号">
                <el-form-item prop="User_Number">
                    <el-input v-model.trim="form.User_Number" placeholder="请输入手机号"></el-input>
                </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="密码">
                <el-form-item prop="Pass_Word">
                    <el-input v-model.trim="form.Pass_Word" placeholder="请输入客户密码"></el-input>
                </el-form-item>
            </el-descriptions-item>
                <el-descriptions-item label="性别">
                    <el-form-item prop="Sex">
                    <el-radio-group v-model.trim="form.Sex">
                        <el-radio label="0">男</el-radio>
                        <el-radio label="1">女</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-descriptions-item>
        </el-descriptions>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:visible',false)">取消</el-button>
        <el-button v-if="tab==0" type="success" @click="Add()">添加联系人</el-button>
        <template v-else>
            <el-button @click="tab=0">返回</el-button>
            <el-button type="primary" @click="submitForm('contract')">提交</el-button>
        </template>
    </span></el-dialog>`,
    props: ['id', 'visible'],
    data() {
        const validator = (rule, value, callback) => {
            if (!validatemobile(this.form.User_Number)) {
                callback(new Error('请输入有效手机号'));
            } else {
                callback();
            }
        }
        return {
            visibleDialog: false,
            tableData: [],
            tab: 0,//0查询 1添加 2修改
            page: {
                SQLSerialNumber: 'P_base_system_user_firstparty',
                Condition: '',
                ExtensionCondition: '',
            },
            total: 0,
            form: {},
            rules: {
                User_Number: [{ required: true, validator, trigger: 'blur' }],
                ID_Name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
            },
        }
    },
    watch: {
        visible() {
            this.visibleDialog = this.visible;
        },
        visibleDialog(val) {
            this.$emit('update:visible', val);
            if (val) {
                this.tab = 0;
                this.page.Condition = window.btoa(encodeURIComponent(this.id));
                this.getList(this.page);
            }
        },
    },
    methods: {
        Add() {
            this.form = {
                User_Number: '',
                ID_Name: '',//表名
                Pass_Word: 'Aa123456',//描述
                Name: '',
                Sex: '0',//0男1女
                Mail: '',
                Creation_Datetime: '',
                Row_Status: '0',
                Children: {
                    base_system_user_role: [{
                        System_User_Role_SerialNumber: '',
                        User_Number: '',
                        Role_SerialNumber: 'firstparty',
                        Other_SerialNumber: '',
                    }],
                }
            }
            this.value = []
            this.tab = 1;
        },
        Edit(User_Number) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                data: {
                    Data: "base_system_user_info",
                    Condition: "User_Number='" + User_Number + "'"
                },
                success: function (data) {
                    if (data.length == 1) {
                        that.form = data[0];
                        that.tab = 2;
                    }
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        Remove(row) {
            const that = this
            this.$confirm('警告！此操作将删除该联系人, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                row.Row_Status = '1';
                $.ajax({
                    headers: requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalSave`,
                    type: 'POST',
                    data: {
                        Data: JSON.stringify({ Modify: { business_department_bank_account: [row] } })
                    },
                    success: function (res) {
                        if (res.Status === 'success') {
                            that.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            that.getList(that.page);
                        } else {
                            that.$message.error("删除失败，请稍后再试")
                        }
                    },
                    complete: function (XMLHttpRequest) {
                        that.loading = false
                        requestPretreatment(XMLHttpRequest, false, () => {
                            that.$message.error("删除失败，请稍后再试")
                        });
                    },
                    dataType: "json"
                })
            }).catch(() => { });
        },
        changeAddress(val) {
            this.form.Enterprise_Province = val[0];
            this.form.Enterprise_City = val[1];
            this.form.Enterprise_County = val[2];
        },
        getList(data) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
                data,
                success: function (Result) {
                    that.tableData = Result;
                    that.total = Result.length;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        submitForm(formName) {
            const that = this;
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    that.loading = true;
                    let data = {};
                    if (that.tab == 1) {
                        that.form.Creation_Datetime = getYMDHMSDate();
                        that.form.Children.base_system_user_role[0].Other_SerialNumber = that.id;
                        data = {
                            Data: JSON.stringify({
                                Add: {
                                    base_system_user_info: [that.form],
                                }
                            })
                        }
                    } else if (that.tab == 2) {
                        data = {
                            Data: JSON.stringify({
                                Modify: {
                                    base_system_user_info: [that.form],
                                }
                            })
                        }
                    }
                    $.ajax({
                        headers: requestHeaders(),
                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                        type: 'POST',
                        data,
                        success: function (res) {
                            if (res.Status === 'success') {
                                that.$message.success("提交成功")
                                that.getList(that.page)
                                that.tab = 0;
                            } else {
                                that.$message.error("提交失败，该手机号已存在")
                            }
                        },
                        complete: function (XMLHttpRequest) {
                            that.loading = false
                            requestPretreatment(XMLHttpRequest, false, () => {
                                that.$message.error("系统繁忙")
                            });
                        },
                        dataType: "json"
                    })
                } else {
                    that.$message({
                        message: sumberError,
                        type: 'warning'
                    })
                    return false;
                }
            })
        }
    }
})
Vue.component('show-detail', {
    template: `<el-dialog title="用户详情信息" id="user" :visible.sync="visibleDialog" width="80vw">
        <div style="display:flex;">
            <div style="width:170px;height:170px;border:1px solid #EBEEF5;flex-shrink:0;display: flex;justify-content: center; align-items: center;">
                <el-image style="width:150px;height:150px;border-radius: 50%;" :preview-src-list="[tableData1.Image]" :src="tableData1.Image">
                    <div slot="error" class="el-image__error">暂未绑定微信</div>
                </el-image>
            </div>
            <el-descriptions style="width:100%" :column="3" border size="small">
                <el-descriptions-item label="用户姓名">
                    <el-tooltip class="item" effect="dark" :content="tableData1.Member_Name" placement="top-start">
                        <el-input :value="tableData1.Member_Name" :disabled="true"></el-input>
                    </el-tooltip>
                </el-descriptions-item>
                <el-descriptions-item label="手机号">
                    <el-tooltip class="item" effect="dark" :content="tableData1.Member_SerialNumber" placement="top-start">
                        <el-input :value="tableData1.Member_SerialNumber" :disabled="true"></el-input>
                    </el-tooltip>
                </el-descriptions-item>
                <el-descriptions-item label="性别">
                    <el-tooltip class="item" effect="dark" :content="tableData1.Sex=='0'?'男':'女'" placement="top-start">
                        <el-input :value="tableData1.Sex=='0'?'男':'女'" :disabled="true"></el-input>
                    </el-tooltip>
                </el-descriptions-item>
                <el-descriptions-item label="注册时间">
                    <el-tooltip class="item" effect="dark" :content="tableData1.Creation_Datetime" placement="top-start">
                        <el-input :value="tableData1.Creation_Datetime" :disabled="true"></el-input>
                    </el-tooltip>
                </el-descriptions-item>
                <el-descriptions-item label="生日">
                    <el-tooltip class="item" effect="dark" :content="tableData1.Birthday?tableData1.Birthday:'暂未录入'" placement="top-start">
                        <el-input :value="tableData1.Birthday?tableData1.Birthday:'暂未录入'" :disabled="true"></el-input>
                    </el-tooltip>
                </el-descriptions-item>
                <el-descriptions-item label="所属部门">
                    <el-tooltip class="item" effect="dark" :content="tableData1.Department_Name?tableData1.Department_Name:'暂无所属部门'" placement="top-start">
                        <el-input :value="tableData1.Department_Name" :disabled="true"></el-input>
                    </el-tooltip>
                </el-descriptions-item>
                <el-descriptions-item label="微信编号">
                    <el-tooltip class="item" effect="dark" :content="tableData1.Open_ID?tableData1.Open_ID:'暂未绑定微信'" placement="top-start">
                        <el-input :value="tableData1.Open_ID?tableData1.Open_ID:'暂未绑定微信'" :disabled="true"></el-input>
                    </el-tooltip>    
                </el-descriptions-item>
                <el-descriptions-item label="微信名称">
                    <el-tooltip class="item" effect="dark" :content="tableData1.Member_Nike?tableData1.Member_Nike:'暂未绑定微信'" placement="top-start">
                        <el-input :value="tableData1.Member_Nike?tableData1.Member_Nike:'暂未绑定微信'" :disabled="true"></el-input>
                    </el-tooltip> 
                </el-descriptions-item>
            </el-descriptions>
        </div>
        <div class="table_titel">
            <div class="titel">消费数据</div>
        </div>
        <el-descriptions style="width:100%" :column="4" border size="small">
            <el-descriptions-item label="下单数">
                <el-input :value="tableData1.sales_order_number" :disabled="true"></el-input>
            </el-descriptions-item>
            <el-descriptions-item label="支付成功数">
                <el-input :value="tableData1.collection_number" :disabled="true"></el-input>
            </el-descriptions-item>
            <el-descriptions-item label="售后次数">
                <el-input :value="tableData1.refund_number" :disabled="true"></el-input>
            </el-descriptions-item>
            <el-descriptions-item label="售后单数">
                <el-input :value="tableData1.refund_number" :disabled="true"></el-input>
            </el-descriptions-item>
        </el-descriptions>
        <el-tabs v-model="activeName" type="border-card" style="margin-top: 15px;">
            <el-tab-pane label="TA的订单" name="1">
                <el-form :inline="true">
                    <el-form-item label="订单编号:">
                        <el-input v-model.trim="form2.Sales_Order_SerialNumber" clearable placeholder="请输入订单编号" />
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="getList2(form2)">查询</el-button>
                    </el-form-item>
                </el-form>
                <el-table v-if="activeName=='1'" :data="tableData2" stripe border height="270px" style="width: 100%">
                    <el-table-column align="center" type="index" label="序号" width="50"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Sales_Order_SerialNumber" label="订单编号"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Quantity" label="商品数量"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Sales_Amount" label="订单金额(元)"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Sales_Date" label="下单时间"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Creation_Datetime" label="状态">
                        <template v-slot="{row}">
                            <el-tag :type="Type(row)[1]">{{Type(row)[0]}}</el-tag>
                        </template>
                    </el-table-column>        
                </el-table>
                <el-pagination style="margin-top: 5px;" background @size-change="handleSizeChange($event,2)"
                    @current-change="handleCurrentChange($event,2)" :current-page="form2.page" :page-sizes="[10 ,20, 30, 50]"
                    :page-size="form2.limit" layout="total, sizes, prev, pager, next, jumper" :total="total2">
                </el-pagination>
            </el-tab-pane>
            <el-tab-pane label="TA的收货地址" name="2">
                <el-table v-if="activeName=='2'" :data="tableData3" stripe border height="332px" style="width: 100%">
                    <el-table-column align="center" type="index" label="序号" width="50"></el-table-column>
                    <el-table-column align="center" min-width="160" prop="Name" label="姓名"></el-table-column>
                    <el-table-column align="center" min-width="160" prop="Phone" label="电话"></el-table-column>
                    <el-table-column align="center" min-width="300" show-overflow-tooltip label="地址">
                        <template v-slot="{row}">
                            {{row.Province}}{{row.City}}{{row.County}}{{row.Details}}
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination style="margin-top: 5px;" background @size-change="handleSizeChange($event,3)"
                    @current-change="handleCurrentChange($event,3)" :current-page="form3.page" :page-sizes="[10 ,20, 30, 50]"
                    :page-size="form3.limit" layout="total, sizes, prev, pager, next, jumper" :total="total3">
                </el-pagination>
            </el-tab-pane>
            <el-tab-pane label="积分记录" name="3">
                <el-table v-if="activeName=='3'" :data="tableData4" stripe border height="332px" style="width: 100%">
                    <el-table-column align="center" type="index" label="序号" width="50"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Activity_Name" label="活动名称"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip width="120" prop="Logistics_Name" label="类型">
                        <template v-slot="{row}">
                            {{parseInt(row.Points) > 0?'收入':'支出'}}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Points" label="数字明细"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Remain_Points" label="活动剩余积分"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Points_Title" label="操作记录"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Notes" label="备注"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Operation_Datetime" label="操作时间">
                        <template v-slot="{row}">
                            {{getYMDHMSDate(row.Operation_Datetime)}}
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination style="margin-top: 5px;" background @size-change="handleSizeChange($event,4)"
                    @current-change="handleCurrentChange($event,4)" :current-page="form4.page" :page-sizes="[10 ,20, 30, 50]"
                    :page-size="form4.limit" layout="total, sizes, prev, pager, next, jumper" :total="total4">
                </el-pagination>
            </el-tab-pane>
            <el-tab-pane label="可参与的活动" name="4">
                <el-table v-if="activeName=='4'" :data="tableData5" stripe border height="332px" style="width: 100%">
                    <el-table-column align="center" type="index" label="序号" width="50"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Activity_Name" label="活动名称"></el-table-column>
                    <el-table-column align="center" show-overflow-tooltip prop="Remain_Points" label="剩余可用积分"></el-table-column>
                </el-table>
                <el-pagination style="margin-top: 5px;" background @size-change="handleSizeChange($event,5)"
                    @current-change="handleCurrentChange($event,5)" :current-page="form.page5" :page-sizes="[10 ,20, 30, 50]"
                    :page-size="form5.limit" layout="total, sizes, prev, pager, next, jumper" :total="total5">
                </el-pagination>
            </el-tab-pane>
        </el-tabs>
        <span slot="footer" class="dialog-footer">
            <el-button @click="$emit('update:visible',false)">取消</el-button>
        </span>
    </el-dialog>`,
    props: ['id', 'visible'],
    data() {
        return {
            visibleDialog: false,
            tableData1: {},//用户详情
            tableData2: [],//订单详情
            tableData3: [],//收货地址
            tableData4: [],//积分记录
            tableData5: [],//可参与的活动
            form: {
                SQLSerialNumber: "A_business_member_detail",
                Condition: '',
                ExtensionCondition: '',
            },
            form2: {//订单详情查询参数
                SQLSerialNumber: "A_business_member_order",
                Condition: '',
                ExtensionCondition: '',
                Sales_Order_SerialNumber: '',
                PaginationNumber: 1,//页数
                RowAmount: 10,//每页数据条数
            },
            form3: {//订单详情查询参数
                SQLSerialNumber: "A_business_member_address",
                Condition: '',
                ExtensionCondition: '',
                PaginationNumber: 1,//页数
                RowAmount: 10,//每页数据条数
            },
            form4: {
                SQLSerialNumber: "P_business_member_points_log",
                Condition: '',
                ExtensionCondition: '',
                PaginationNumber: 1,//页数
                RowAmount: 10,//每页数据条数
            },
            form5: {
                SQLSerialNumber: "A_business_activity_member",
                Condition: '',
                ExtensionCondition: '',
                PaginationNumber: 1,//页数
                RowAmount: 10,//每页数据条数
            },
            total2: 0,
            total3: 0,
            total4: 0,
            total5: 0,
            activeName: '1',
        }
    },
    computed: {
        Type() {
            return function (row) {
                if (row.Refund_Type == '1') {
                    return ["已退款", "info"]
                } else {
                    let str = row.Row_Status;
                    switch (str.charAt(1)) {
                        case "0":
                            return ["待付款", ""];
                        case "1":
                            return ["待付款", ""];
                        case "2":
                            return ["待付款", ""];
                        case "3":
                            return ["已付款", "success"];
                        case "4":
                            return ["已发货", "warning"];
                        case "5":
                            return ["已完成", "info"];
                        case "6":
                            return ["已取消", "danger"];
                        case "7":
                            return ["已取消", "danger"];
                        default:
                            return ""
                    }
                }
            }
        }
    },
    watch: {
        visible() {
            this.visibleDialog = this.visible
        },
        visibleDialog(val) {
            this.$emit('update:visible', val)
            if (val) {
                this.activeName = '1';
                this.tableData1 = {};
                this.form.Condition = window.btoa(unescape(encodeURIComponent(this.id)));
                this.form3.Condition = window.btoa(unescape(encodeURIComponent(this.id)));
                this.form4.Condition = window.btoa(unescape(encodeURIComponent(`${this.id},${this.id},%%`)));
                this.form5.Condition = window.btoa(unescape(encodeURIComponent(this.id)));
                this.getData(this.form);
                this.getList2(this.form2);
                this.getList3(this.form3);
                this.getList4(this.form4);
                this.getList5(this.form5);
            }
        },
    },
    methods: {
        getData(data) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
                type: 'POST',
                data,
                success: function (data) {
                    if (data.length == 1) {
                        that.tableData1 = data[0];
                    }
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        getList2(form) {//TA的订单
            const that = this;
            let data = deepClone(form);
            data.Condition = window.btoa(unescape(encodeURIComponent(`${this.id},%${data.Sales_Order_SerialNumber}%`)));
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                data,
                success: function (Result) {
                    that.tableData2 = Result.Rows;
                    that.total2 = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        getList3(data) {//TA的收货地址
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                data,
                success: function (Result) {
                    that.tableData3 = Result.Rows;
                    that.total3 = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        getList4(data) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                data,
                success: function (Result) {
                    that.tableData4 = Result.Rows;
                    that.total4 = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        getList5(data) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                data,
                success: function (Result) {
                    that.tableData5 = Result.Rows;
                    that.total5 = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        handleSizeChange(val, id) {
            console.log(val, id);
            this['form' + id].PaginationNumber = 1;
            this['form' + id].RowAmount = val;
            this['getList' + id](this['form' + id])
        },
        handleCurrentChange(val, id) {
            this['form' + id].PaginationNumber = val;
            this['getList' + id](this['form' + id])
        },
    }
})
new Vue({
    el: '#app',
    data() {
        return {
            form: {
                SQLSerialNumber: "P_business_member_info",
                PaginationNumber: 1,//页数
                RowAmount: 20,//每页数据条数
                Member_SerialNumber: '',
                Member_Name: '',
                Department_SerialNumber: [],
                Condition: '',
                ExtensionCondition: '',
            },
            total: 0,
            tableData: [],	//表格数据
            treeData: [],
            defaultProps: {
                children: 'Children',
                label: 'Department_Name'
            },
            department: {//部门
                Level: 1,
                Parent_SerialNumber: '',
            },
            node:null,
            visibleAddMember: false,//添加用户
            visibleEditMember: false,//修改用户
            visibleAddDepartment: false,//添加部门
            visibleEditDepartment: false,//修改部门
            visibleIntegral: false,//积分
            visibleInvoice: false,//发票
            visibleUser: false,//部门联系人
            visibleDetail: false,//用户详情信息
            Member_SerialNumber: '',//选择手机号
            Department_SerialNumber: '',//选择部门
            Open_ID: '',
            isTree: true,
        }
    },
    mounted() {
        this.getList(this.form);//前端分页
        this.getData();
    },
    methods: {
        showTree() {
            this.isTree = !this.isTree
        },
        onSerach() {			//查询方法
            this.form.PaginationNumber = 1;
            this.getList(this.form)
        },
        handleSizeChange(val) {
            this.form.PaginationNumber = 1;
            this.form.RowAmount = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.PaginationNumber = val;
            this.getList(this.form)
        },
        getData() {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/getAllDepartmentByUserName?UserName=&ParentNumber=`,
                type: 'GET',
                success: function (data) {
                    console.log(data);
                    that.treeData = data;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        getList(form) {//换页方法
            const that = this
            let data = deepClone(form);
            let str = "";
            if (data.Department_SerialNumber.length > 0) {
                data.Department_SerialNumber.forEach((item, index) => {
                    if (index == 0) {
                        str = str + " where (business_member_department.Department_SerialNumber='" + item + "'";
                    } else {
                        str = str + "\r\nor business_member_department.Department_SerialNumber='" + item + "'";
                    }
                })
                str = str + ")";
            }
            data.Condition = window.btoa(unescape(encodeURIComponent(`%${data.Member_SerialNumber}%,%${data.Member_Name}%`)));
            data.ExtensionCondition = window.btoa(unescape(encodeURIComponent(str)));
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                data,
                success: function (Result) {
                    that.tableData = Result.Rows;
                    that.total = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        Edit(Member_SerialNumber) {
            this.Member_SerialNumber = Member_SerialNumber;
            this.visibleEditMember = true;
        },
        Integral(row) {
            this.Member_SerialNumber = row.Member_SerialNumber;
            this.Open_ID = row.Open_ID;
            this.visibleIntegral = true;
        },
        showDetail(row) {
            this.Member_SerialNumber = row.Member_SerialNumber;
            this.visibleDetail = true;
        },
        Remove(row) {
            const that = this
            this.$confirm('警告！此操作将删除该用户, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                row.Row_Status = '1';
                $.ajax({
                    headers: requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalSave`,
                    type: 'POST',
                    data: {
                        Data: JSON.stringify({ 
                            Modify: { business_member_info: [row] } ,
                            Add: { base_operation_log: [generateLog('删除用户信息', '平台端操作', 'business_member_info', JSON.stringify({ Modify: { business_member_info: [row] } }))] }
                        })
                    },
                    success: function (res) {
                        if (res.Status === 'success') {
                            that.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            that.getList(that.form);
                        } else {
                            that.$message.error("删除失败，请稍后再试")
                        }
                    },
                    error: function () {
                        that.$message.error("删除失败，请稍后再试")
                    },
                    complete: function (XMLHttpRequest) {
                        that.loading = false
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json"
                })
            }).catch(() => { });
        },
        clickDepartment(command, node, data) {//部门下单菜单选项
            if (command == 'department') {
                console.log(node);
                this.add_department(node, data)
            } else if (command == 'user') {
                this.add_user(data)
            } else if (command == 'edit') {
                this.edit_department(data.Department_SerialNumber)
            } else if (command == 'invoice') {
                this.invoice(data.Department_SerialNumber)
            } else if (command == 'remove') {
                this.remove_department(data)
            }
        },
        remove_department(row) {
            const that = this;
            this.$confirm('警告！此操作将删除该部门, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                let arr = [];
                this.recursion([row], 'Department_SerialNumber', arr);
                let sql = "";
                arr.forEach((item, index) => {
                    if (index == 0) {
                        sql = sql + "Department_SerialNumber='" + item + "'\r\n"
                    } else {
                        sql = sql + " or Department_SerialNumber='" + item + "'\r\n"
                    }
                })
                $.ajax({
                    headers: requestHeaders(),
                    type: 'POST',
                    url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                    data: {
                        Data: "business_department_info",
                        Condition: sql
                    },
                    success: function (business_department_info) {
                        business_department_info.forEach(item => {
                            item.Row_Status = '1'
                        })
                        $.ajax({
                            headers: requestHeaders(),
                            url: `${BASE_URL2}/generalBusiness/generalSave`,
                            type: 'POST',
                            data: {
                                Data: JSON.stringify({ 
                                    Modify: { business_department_info } ,
                                    Add: { base_operation_log: [generateLog('删除部门信息', '平台端操作', 'business_department_info', JSON.stringify({ Modify: { business_department_info } }))] }
                                })
                            },
                            success: function (res) {
                                if (res.Status === 'success') {
                                    that.$message({
                                        type: 'success',
                                        message: '删除成功!'
                                    });
                                    that.getData();
                                } else {
                                    that.$message.error("删除失败，请稍后再试")
                                }
                            },
                            error: function () {
                                that.$message.error("删除失败，请稍后再试")
                            },
                            complete: function (XMLHttpRequest) {
                                that.loading = false
                                requestPretreatment(XMLHttpRequest);
                            },
                            dataType: "json"
                        })
                    },
                    complete: function (XMLHttpRequest) {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json"
                });
            }).catch(() => { });
        },
        add_department(node, data) {
            if (node && data) {
                this.department.Parent_SerialNumber = data.Department_SerialNumber;
                this.department.Level = node.level + 1;
            } else {
                this.department.Parent_SerialNumber = '';
                this.department.Level = 1;
            }
            this.node = node;
            this.visibleAddDepartment = true;
        },
        edit_department(Department_SerialNumber) {
            this.Department_SerialNumber = Department_SerialNumber;
            this.visibleEditDepartment = true;
        },
        invoice(Department_SerialNumber) {//开票管理
            this.Department_SerialNumber = Department_SerialNumber;
            this.visibleInvoice = true;
        },
        add_user(data) {//联系人管理
            this.Department_SerialNumber = data.Department_SerialNumber
            this.visibleUser = true;
        },
        downloadTemplate(command) {
            if (command == 'member') {
                window.location.href = './download/导入会员模板表.新.xlsx'
            } else if (command == "Points") {
                window.location.href = '../../points/points_log/download/内部用户积分变动模板.xlsx';
            }
        },
        importTemplate(command) {
            if (command == 'member') {
                window.location.href = './import1.html'
            } else if (command == "Points") {
                window.location.href = '../../points/points_log/import.html';
            }
        },
        handleNode(row) {//点击部门
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/getAllDepartmentByUserName?UserName=&ParentNumber=${row.Department_SerialNumber}`,
                type: 'GET',
                success: function (data) {
                    let arr2 = []
                    that.recursion(data, 'Department_SerialNumber', arr2);
                    that.form.Department_SerialNumber = [...arr2, row.Department_SerialNumber];
                    that.getList(that.form);
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        recursion(arr1, str, arr2) {
            arr1.forEach(item => {
                arr2.push(item[str]);
                if (item.Children && item.Children.length > 0) {
                    this.recursion(item.Children, str, arr2);
                }
            });
        },
        Export(){
            const that = this;
            this.loading = true;
            let data = deepClone(this.form);
            let str = "";
            if (data.Department_SerialNumber.length > 0) {
                data.Department_SerialNumber.forEach((item, index) => {
                    if (index == 0) {
                        str = str + " where (business_member_department.Department_SerialNumber='" + item + "'";
                    } else {
                        str = str + "\r\nor business_member_department.Department_SerialNumber='" + item + "'";
                    }
                })
                str = str + ")";
            }
            data.Condition = window.btoa(unescape(encodeURIComponent(`%${data.Member_SerialNumber}%,%${data.Member_Name}%`)));
            data.ExtensionCondition = window.btoa(unescape(encodeURIComponent(str)));
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
                type: 'POST',
                data,
                success: function (Result) {
                    if (Result.length > 0) {
                        let ExportData = [];
                        console.log(Result);
                        // console.log(ExportData);
                        const wb = XLSX.utils.book_new();
                        const ws_data = [
                            ["姓名", "手机号", "微信昵称", "所属部门", "消费总额", "注册时间", "邮箱"]
                        ];
                        Result.forEach(i => {
                            ws_data.push([
                                i.Member_Name,
                                i.Member_SerialNumber,
                                i.Member_Nike,
                                i.Department_Name,
                                i.Sales_Amount,
                                i.Creation_Datetime,
                                i.Email
                            ])
                        })
                        const ws = XLSX.utils.aoa_to_sheet(ws_data);
                        ws['!cols'] = [];
                        ws_data[0].forEach(item => {
                            ws['!cols'].push({ alignment: { horizontal: "center" }, wpx: 150 });
                        })
                        XLSX.utils.book_append_sheet(wb, ws, '用户信息表');
                        XLSX.writeFile(wb, "用户信息表" + (+new Date()) + ".xlsx");
                        that.$message({
                            message: '已成功导出',
                            type: 'success'
                        })

                    } else {
                        that.$message({
                            message: '暂无可导出的数据',
                            type: 'warning'
                        })
                    }
                },
                complete: function (XMLHttpRequest) {
                    that.loading = false;
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        }
    },
})